package de.tc.stammdatenverwaltung.gui.kontakthistory;

import de.tc.stammdatenverwaltung.functions.commonFunctions;
import de.tc.stammdatenverwaltung.functions.myHistTableModel;
import javax.swing.table.DefaultTableModel;

public class Kontakthistorie extends javax.swing.JDialog {

    private int ID = -1; //KontaktID

    public static String selectSQL = "select ID, DATUM, NACHRICHT, Art, EIN from KONTAKTHISTORIE ";
    public static DefaultTableModel dtm = new myHistTableModel();

    public Kontakthistorie(java.awt.Frame parent, boolean modal, int id, String name)
    {
      super(parent, modal);
      initComponents();

      ID = id;

      jTable1.setModel(dtm);
      jScrollPane1.setViewportView(jTable1);

      commonFunctions.load_query_to_table(selectSQL+ "where IDKONTAKT = " + ID + " order by datum desc",
        jTable1, dtm );
      
      setTitle("Kontakthistory zu " + name);
    }

    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jButton1 = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTable1 = new javax.swing.JTable();
    jButton2 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    jButton1.setText("Eintrag hinzufügen");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    jTable1.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
        {null, null, null, null},
        {null, null, null, null}
      },
      new String [] {
        "Titel 1", "Titel 2", "Titel 3", "Titel 4"
      }
    ));
    jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_NEXT_COLUMN);
    jTable1.setDoubleBuffered(true);
    jTable1.setFillsViewportHeight(true);
    jScrollPane1.setViewportView(jTable1);

    jButton2.setText("Eintrag anzeigen");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 669, Short.MAX_VALUE)
      .addGroup(layout.createSequentialGroup()
        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
        .addGap(18, 18, 18)
        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jButton1)
          .addComponent(jButton2))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
      addKontaktEintrag ake = new addKontaktEintrag(null, true, ID);
      ake.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
      int nid = commonFunctions.markedMessage.elementAt(jTable1.getSelectedRow());
      showKontaktEintrag ske = new showKontaktEintrag(null, true, nid, ID);
      ske.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JScrollPane jScrollPane1;
  public static javax.swing.JTable jTable1;
  // End of variables declaration//GEN-END:variables

}
